const ProjectModel = require("./models/ProjectModel");

/**
 * 向数据库插入一条数据
 * @param {object} project 
 * @returns 
 */
exports.createProjectDao = async (project) => {
    return await ProjectModel.create(project);
}

/**
 * 获取所有数据
 * @returns 
 */
exports.getAllProjectDao = async () => {
    return await ProjectModel.findAll();
}

/**
 * 修改数据
 * @param {object} newProject 
 * @param {number} id 
 * @returns 
 */
exports.updateProjectDao = async (newProject, id) => {
    return await ProjectModel.update(newProject, {
        where: {
            id
        }
    })
}

/**
 * 删除一片文章
 * @param {number} id 
 * @returns 
 */
exports.deleteProjectDao = async (id) => {
    return await ProjectModel.destroy({
        where: {
            id
        }
    })
}

exports.getOneProjectDao = async (id) => {
    return await ProjectModel.findByPk(id);
}